package com.hclc.config.util;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * @ClassName PrintStackTraceUtil
 * @Author: yurj
 * @Mail：1638234804@qq.com
 * @Date: Create in 16:14 2020-4-8
 * @version: 1.0
 */
public class PrintStackTraceUtil {
    /**
     * 打印异常堆栈信息
     * @param t
     * @return java.lang.String
     * @author yurj
     * @mail 1638234804@qq.com
     * @version 1.0
     * @date 2020-4-8 16:15
     */

    public static String getTrace(Throwable t) {
        StringBuffer buffer = new StringBuffer();
        buffer.append("异常类型 : ->  ");
        buffer.append(t.getClass().getName());
        buffer.append(" 【分割符】     错误信息 : ->  ");
        buffer.append(t.getMessage());
        buffer.append(" 【分割符】     堆栈信息 : ->  ");
        StringWriter stringWriter = new StringWriter();
        PrintWriter writer = new PrintWriter(stringWriter);
        t.printStackTrace(writer);
        buffer.append(stringWriter.getBuffer());
        return buffer.toString();
    }
}
